# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Maintainer: Christian Heusel <gromit@archlinux.org>
# Contributor: Kr1ss $(echo \<kr1ss+x-yandex+com\>|sed s/\+/./g\;s/\-/@/)
# Contributor: Alexander Görtz <aur@nyloc.de>
# Contributor: Dan Beste <dan.ray.beste@gmail.com>
# Contributor: Julien Nicoulaud <julien dot nicoulaud at gmail dot com>
# Contributor: stef204 <https://aur.archlinux.org/account/stef204>

pkgname=borgmatic
_commit=fdb353d3581fcea521d6fc2a0d505fac8a432253
pkgver=1.8.5
pkgrel=1
pkgdesc='Simple, configuration-driven backup software for servers and workstations'
arch=('any')
url=https://torsion.org/borgmatic
license=('GPL3')
depends=(
  'borg'
  'python-colorama'
  'python-jsonschema'
  'python-requests'
  'python-ruamel-yaml'
  'python-setuptools'
)
makedepends=('git' 'python-build' 'python-installer' 'python-wheel')
checkdepends=('apprise' 'python-flexmock' 'python-pytest')
optdepends=(
  'apprise: for Apprise notifications'
  'python-llfuse: for mount action'
)
source=("git+https://projects.torsion.org/borgmatic-collective/borgmatic.git#tag=$_commit")
b2sums=('SKIP')

prepare() {
  cd $pkgname
  sed -i 's,root/.local,usr,' sample/systemd/borgmatic{,-user}.service
}

build() {
  cd $pkgname
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd $pkgname
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  PATH="$PWD/test-env/bin:$PATH" test-env/bin/python -m pytest -c /dev/null \
    --ignore=tests/end-to-end
}

package() {
  cd $pkgname
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 -t "$pkgdir"/usr/lib/systemd/system sample/systemd/borgmatic.{service,timer}
  install -Dm644 -t "$pkgdir"/usr/lib/systemd/user sample/systemd/borgmatic-user.{service,timer}

  install -d "$pkgdir"/usr/share/{bash-completion/completions,fish/vendor_completions.d}
  ./test-env/bin/borgmatic --bash-completion > \
    "$pkgdir"/usr/share/bash-completion/completions/$pkgname
  ./test-env/bin/borgmatic --fish-completion > \
    "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
}
